home *** CD-ROM | disk | FTP | other *** search
/ One Click 11 / OneClick11.iso / Bancos de Dados / Conversao / Mysql2Excel / Setup.exe / Mysql2Excel.exe / pre.pyc (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2003-06-23  |  26.3 KB  |  715 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.2)
  3.  
  4. '''Support for regular expressions (RE).
  5.  
  6. This module provides regular expression matching operations similar to
  7. those found in Perl. It\'s 8-bit clean: the strings being processed may
  8. contain both null bytes and characters whose high bit is set. Regular
  9. expression pattern strings may not contain null bytes, but can specify
  10. the null byte using the \\\\number notation. Characters with the high
  11. bit set may be included.
  12.  
  13. Regular expressions can contain both special and ordinary
  14. characters. Most ordinary characters, like "A", "a", or "0", are the
  15. simplest regular expressions; they simply match themselves. You can
  16. concatenate ordinary characters, so last matches the string \'last\'.
  17.  
  18. The special characters are:
  19.     "."      Matches any character except a newline.
  20.     "^"      Matches the start of the string.
  21.     "$"      Matches the end of the string.
  22.     "*"      Matches 0 or more (greedy) repetitions of the preceding RE.
  23.              Greedy means that it will match as many repetitions as possible.
  24.     "+"      Matches 1 or more (greedy) repetitions of the preceding RE.
  25.     "?"      Matches 0 or 1 (greedy) of the preceding RE.
  26.     *?,+?,?? Non-greedy versions of the previous three special characters.
  27.     {m,n}    Matches from m to n repetitions of the preceding RE.
  28.     {m,n}?   Non-greedy version of the above.
  29.     "\\\\"      Either escapes special characters or signals a special sequence.
  30.     []       Indicates a set of characters.
  31.              A "^" as the first character indicates a complementing set.
  32.     "|"      A|B, creates an RE that will match either A or B.
  33.     (...)    Matches the RE inside the parentheses.
  34.              The contents can be retrieved or matched later in the string.
  35.     (?iLmsx) Set the I, L, M, S, or X flag for the RE.
  36.     (?:...)  Non-grouping version of regular parentheses.
  37.     (?P<name>...) The substring matched by the group is accessible by name.
  38.     (?P=name)     Matches the text matched earlier by the group named name.
  39.     (?#...)  A comment; ignored.
  40.     (?=...)  Matches if ... matches next, but doesn\'t consume the string.
  41.     (?!...)  Matches if ... doesn\'t match next.
  42.  
  43. The special sequences consist of "\\\\" and a character from the list
  44. below. If the ordinary character is not on the list, then the
  45. resulting RE will match the second character.
  46.     \\\\number  Matches the contents of the group of the same number.
  47.     \\\\A       Matches only at the start of the string.
  48.     \\\\Z       Matches only at the end of the string.
  49.     \\\\b       Matches the empty string, but only at the start or end of a word.
  50.     \\\\B       Matches the empty string, but not at the start or end of a word.
  51.     \\\\d       Matches any decimal digit; equivalent to the set [0-9].
  52.     \\\\D       Matches any non-digit character; equivalent to the set [^0-9].
  53.     \\\\s       Matches any whitespace character; equivalent to [ \\\\t\\\\n\\\\r\\\\f\\\\v].
  54.     \\\\S       Matches any non-whitespace character; equiv. to [^ \\\\t\\\\n\\\\r\\\\f\\\\v].
  55.     \\\\w       Matches any alphanumeric character; equivalent to [a-zA-Z0-9_].
  56.              With LOCALE, it will match the set [0-9_] plus characters defined
  57.              as letters for the current locale.
  58.     \\\\W       Matches the complement of \\\\w.
  59.     \\\\\\\\       Matches a literal backslash.
  60.  
  61. This module exports the following functions:
  62.     match    Match a regular expression pattern to the beginning of a string.
  63.     search   Search a string for the presence of a pattern.
  64.     sub      Substitute occurrences of a pattern found in a string.
  65.     subn     Same as sub, but also return the number of substitutions made.
  66.     split    Split a string by the occurrences of a pattern.
  67.     findall  Find all occurrences of a pattern in a string.
  68.     compile  Compile a pattern into a RegexObject.
  69.     escape   Backslash all non-alphanumerics in a string.
  70.  
  71. This module exports the following classes:
  72.     RegexObject    Holds a compiled regular expression pattern.
  73.     MatchObject    Contains information about pattern matches.
  74.  
  75. Some of the functions in this module takes flags as optional parameters:
  76.     I  IGNORECASE  Perform case-insensitive matching.
  77.     L  LOCALE      Make \\w, \\W, \\b, \\B, dependent on the current locale.
  78.     M  MULTILINE   "^" matches the beginning of lines as well as the string.
  79.                    "$" matches the end of lines as well as the string.
  80.     S  DOTALL      "." matches any character at all, including the newline.
  81.     X  VERBOSE     Ignore whitespace and comments for nicer looking RE\'s.
  82.  
  83. This module also defines an exception \'error\'.
  84.  
  85. '''
  86. import sys
  87. from pcre import *
  88. __all__ = [
  89.     'match',
  90.     'search',
  91.     'sub',
  92.     'subn',
  93.     'split',
  94.     'findall',
  95.     'escape',
  96.     'compile',
  97.     'I',
  98.     'L',
  99.     'M',
  100.     'S',
  101.     'X',
  102.     'IGNORECASE',
  103.     'LOCALE',
  104.     'MULTILINE',
  105.     'DOTALL',
  106.     'VERBOSE',
  107.     'error']
  108. I = IGNORECASE
  109. L = LOCALE
  110. M = MULTILINE
  111. S = DOTALL
  112. X = VERBOSE
  113. _cache = { }
  114. _MAXCACHE = 20
  115.  
  116. def _cachecompile(pattern, flags = 0):
  117.     key = (pattern, flags)
  118.     
  119.     try:
  120.         return _cache[key]
  121.     except KeyError:
  122.         pass
  123.  
  124.     value = compile(pattern, flags)
  125.     if len(_cache) >= _MAXCACHE:
  126.         _cache.clear()
  127.     
  128.     _cache[key] = value
  129.     return value
  130.  
  131.  
  132. def match(pattern, string, flags = 0):
  133.     '''match (pattern, string[, flags]) -> MatchObject or None
  134.  
  135.     If zero or more characters at the beginning of string match the
  136.     regular expression pattern, return a corresponding MatchObject
  137.     instance. Return None if the string does not match the pattern;
  138.     note that this is different from a zero-length match.
  139.  
  140.     Note: If you want to locate a match anywhere in string, use
  141.     search() instead.
  142.  
  143.     '''
  144.     return _cachecompile(pattern, flags).match(string)
  145.  
  146.  
  147. def search(pattern, string, flags = 0):
  148.     '''search (pattern, string[, flags]) -> MatchObject or None
  149.  
  150.     Scan through string looking for a location where the regular
  151.     expression pattern produces a match, and return a corresponding
  152.     MatchObject instance. Return None if no position in the string
  153.     matches the pattern; note that this is different from finding a
  154.     zero-length match at some point in the string.
  155.  
  156.     '''
  157.     return _cachecompile(pattern, flags).search(string)
  158.  
  159.  
  160. def sub(pattern, repl, string, count = 0):
  161.     '''sub(pattern, repl, string[, count=0]) -> string
  162.  
  163.     Return the string obtained by replacing the leftmost
  164.     non-overlapping occurrences of pattern in string by the
  165.     replacement repl. If the pattern isn\'t found, string is returned
  166.     unchanged. repl can be a string or a function; if a function, it
  167.     is called for every non-overlapping occurrence of pattern. The
  168.     function takes a single match object argument, and returns the
  169.     replacement string.
  170.  
  171.     The pattern may be a string or a regex object; if you need to
  172.     specify regular expression flags, you must use a regex object, or
  173.     use embedded modifiers in a pattern; e.g.
  174.     sub("(?i)b+", "x", "bbbb BBBB") returns \'x x\'.
  175.  
  176.     The optional argument count is the maximum number of pattern
  177.     occurrences to be replaced; count must be a non-negative integer,
  178.     and the default value of 0 means to replace all occurrences.
  179.  
  180.     '''
  181.     if type(pattern) == type(''):
  182.         pattern = _cachecompile(pattern)
  183.     
  184.     return pattern.sub(repl, string, count)
  185.  
  186.  
  187. def subn(pattern, repl, string, count = 0):
  188.     '''subn(pattern, repl, string[, count=0]) -> (string, num substitutions)
  189.  
  190.     Perform the same operation as sub(), but return a tuple
  191.     (new_string, number_of_subs_made).
  192.  
  193.     '''
  194.     if type(pattern) == type(''):
  195.         pattern = _cachecompile(pattern)
  196.     
  197.     return pattern.subn(repl, string, count)
  198.  
  199.  
  200. def split(pattern, string, maxsplit = 0):
  201.     '''split(pattern, string[, maxsplit=0]) -> list of strings
  202.  
  203.     Split string by the occurrences of pattern. If capturing
  204.     parentheses are used in pattern, then the text of all groups in
  205.     the pattern are also returned as part of the resulting list. If
  206.     maxsplit is nonzero, at most maxsplit splits occur, and the
  207.     remainder of the string is returned as the final element of the
  208.     list.
  209.  
  210.     '''
  211.     if type(pattern) == type(''):
  212.         pattern = _cachecompile(pattern)
  213.     
  214.     return pattern.split(string, maxsplit)
  215.  
  216.  
  217. def findall(pattern, string):
  218.     '''findall(pattern, string) -> list
  219.  
  220.     Return a list of all non-overlapping matches of pattern in
  221.     string. If one or more groups are present in the pattern, return a
  222.     list of groups; this will be a list of tuples if the pattern has
  223.     more than one group. Empty matches are included in the result.
  224.  
  225.     '''
  226.     if type(pattern) == type(''):
  227.         pattern = _cachecompile(pattern)
  228.     
  229.     return pattern.findall(string)
  230.  
  231.  
  232. def escape(pattern):
  233.     '''escape(string) -> string
  234.  
  235.     Return string with all non-alphanumerics backslashed; this is
  236.     useful if you want to match an arbitrary literal string that may
  237.     have regular expression metacharacters in it.
  238.  
  239.     '''
  240.     result = list(pattern)
  241.     for i in range(len(pattern)):
  242.         char = pattern[i]
  243.         if not char.isalnum():
  244.             if char == '\x00':
  245.                 result[i] = '\\000'
  246.             else:
  247.                 result[i] = '\\' + char
  248.         
  249.     
  250.     return ''.join(result)
  251.  
  252.  
  253. def compile(pattern, flags = 0):
  254.     '''compile(pattern[, flags]) -> RegexObject
  255.  
  256.     Compile a regular expression pattern into a regular expression
  257.     object, which can be used for matching using its match() and
  258.     search() methods.
  259.  
  260.     '''
  261.     groupindex = { }
  262.     code = pcre_compile(pattern, flags, groupindex)
  263.     return RegexObject(pattern, flags, code, groupindex)
  264.  
  265.  
  266. class RegexObject:
  267.     '''Holds a compiled regular expression pattern.
  268.  
  269.     Methods:
  270.     match    Match the pattern to the beginning of a string.
  271.     search   Search a string for the presence of the pattern.
  272.     sub      Substitute occurrences of the pattern found in a string.
  273.     subn     Same as sub, but also return the number of substitutions made.
  274.     split    Split a string by the occurrences of the pattern.
  275.     findall  Find all occurrences of the pattern in a string.
  276.  
  277.     '''
  278.     
  279.     def __init__(self, pattern, flags, code, groupindex):
  280.         self.code = code
  281.         self.flags = flags
  282.         self.pattern = pattern
  283.         self.groupindex = groupindex
  284.  
  285.     
  286.     def search(self, string, pos = 0, endpos = None):
  287.         '''search(string[, pos][, endpos]) -> MatchObject or None
  288.  
  289.         Scan through string looking for a location where this regular
  290.         expression produces a match, and return a corresponding
  291.         MatchObject instance. Return None if no position in the string
  292.         matches the pattern; note that this is different from finding
  293.         a zero-length match at some point in the string. The optional
  294.         pos and endpos parameters have the same meaning as for the
  295.         match() method.
  296.  
  297.         '''
  298.         if endpos is None or endpos > len(string):
  299.             endpos = len(string)
  300.         
  301.         if endpos < pos:
  302.             endpos = pos
  303.         
  304.         regs = self.code.match(string, pos, endpos, 0)
  305.         if regs is None:
  306.             return None
  307.         
  308.         self._num_regs = len(regs)
  309.         return MatchObject(self, string, pos, endpos, regs)
  310.  
  311.     
  312.     def match(self, string, pos = 0, endpos = None):
  313.         """match(string[, pos][, endpos]) -> MatchObject or None
  314.  
  315.         If zero or more characters at the beginning of string match
  316.         this regular expression, return a corresponding MatchObject
  317.         instance. Return None if the string does not match the
  318.         pattern; note that this is different from a zero-length match.
  319.  
  320.         Note: If you want to locate a match anywhere in string, use
  321.         search() instead.
  322.  
  323.         The optional second parameter pos gives an index in the string
  324.         where the search is to start; it defaults to 0.  This is not
  325.         completely equivalent to slicing the string; the '' pattern
  326.         character matches at the real beginning of the string and at
  327.         positions just after a newline, but not necessarily at the
  328.         index where the search is to start.
  329.  
  330.         The optional parameter endpos limits how far the string will
  331.         be searched; it will be as if the string is endpos characters
  332.         long, so only the characters from pos to endpos will be
  333.         searched for a match.
  334.  
  335.         """
  336.         if endpos is None or endpos > len(string):
  337.             endpos = len(string)
  338.         
  339.         if endpos < pos:
  340.             endpos = pos
  341.         
  342.         regs = self.code.match(string, pos, endpos, ANCHORED)
  343.         if regs is None:
  344.             return None
  345.         
  346.         self._num_regs = len(regs)
  347.         return MatchObject(self, string, pos, endpos, regs)
  348.  
  349.     
  350.     def sub(self, repl, string, count = 0):
  351.         """sub(repl, string[, count=0]) -> string
  352.  
  353.         Return the string obtained by replacing the leftmost
  354.         non-overlapping occurrences of the compiled pattern in string
  355.         by the replacement repl. If the pattern isn't found, string is
  356.         returned unchanged.
  357.  
  358.         Identical to the sub() function, using the compiled pattern.
  359.  
  360.         """
  361.         return self.subn(repl, string, count)[0]
  362.  
  363.     
  364.     def subn(self, repl, source, count = 0):
  365.         '''subn(repl, string[, count=0]) -> tuple
  366.  
  367.         Perform the same operation as sub(), but return a tuple
  368.         (new_string, number_of_subs_made).
  369.  
  370.         '''
  371.         if count < 0:
  372.             raise error, 'negative substitution count'
  373.         
  374.         if count == 0:
  375.             count = sys.maxint
  376.         
  377.         n = 0
  378.         pos = 0
  379.         lastmatch = -1
  380.         results = []
  381.         end = len(source)
  382.         if type(repl) is type(''):
  383.             
  384.             try:
  385.                 repl = pcre_expand(_Dummy, repl)
  386.             except error:
  387.                 m = MatchObject(self, source, 0, end, [])
  388.                 
  389.                 repl = lambda m, repl = repl, expand = pcre_expand: expand(m, repl)
  390.  
  391.             m = None
  392.         else:
  393.             m = MatchObject(self, source, 0, end, [])
  394.         match = self.code.match
  395.         append = results.append
  396.         while n < count and pos <= end:
  397.             regs = match(source, pos, end, 0)
  398.             if not regs:
  399.                 break
  400.             
  401.             self._num_regs = len(regs)
  402.             (i, j) = regs[0]
  403.             if j == j:
  404.                 pass
  405.             elif j == lastmatch:
  406.                 pos = pos + 1
  407.                 append(source[lastmatch:pos])
  408.                 continue
  409.             
  410.             if pos < i:
  411.                 append(source[pos:i])
  412.             
  413.             if m:
  414.                 m.pos = pos
  415.                 m.regs = regs
  416.                 append(repl(m))
  417.             else:
  418.                 append(repl)
  419.             pos = lastmatch = j
  420.             if i == j:
  421.                 pos = pos + 1
  422.                 append(source[lastmatch:pos])
  423.             
  424.             n = n + 1
  425.         append(source[pos:])
  426.         return (''.join(results), n)
  427.  
  428.     
  429.     def split(self, source, maxsplit = 0):
  430.         '''split(source[, maxsplit=0]) -> list of strings
  431.  
  432.         Split string by the occurrences of the compiled pattern. If
  433.         capturing parentheses are used in the pattern, then the text
  434.         of all groups in the pattern are also returned as part of the
  435.         resulting list. If maxsplit is nonzero, at most maxsplit
  436.         splits occur, and the remainder of the string is returned as
  437.         the final element of the list.
  438.  
  439.         '''
  440.         if maxsplit < 0:
  441.             raise error, 'negative split count'
  442.         
  443.         if maxsplit == 0:
  444.             maxsplit = sys.maxint
  445.         
  446.         n = 0
  447.         pos = 0
  448.         lastmatch = 0
  449.         results = []
  450.         end = len(source)
  451.         match = self.code.match
  452.         append = results.append
  453.         while n < maxsplit:
  454.             regs = match(source, pos, end, 0)
  455.             if not regs:
  456.                 break
  457.             
  458.             (i, j) = regs[0]
  459.             if i == j:
  460.                 if pos >= end:
  461.                     break
  462.                 
  463.                 pos = pos + 1
  464.                 continue
  465.             
  466.             append(source[lastmatch:i])
  467.             rest = regs[1:]
  468.             if rest:
  469.                 for a, b in rest:
  470.                     if a == -1 or b == -1:
  471.                         group = None
  472.                     else:
  473.                         group = source[a:b]
  474.                     append(group)
  475.                 
  476.             
  477.             pos = lastmatch = j
  478.             n = n + 1
  479.         append(source[lastmatch:])
  480.         return results
  481.  
  482.     
  483.     def findall(self, source):
  484.         '''findall(source) -> list
  485.  
  486.         Return a list of all non-overlapping matches of the compiled
  487.         pattern in string. If one or more groups are present in the
  488.         pattern, return a list of groups; this will be a list of
  489.         tuples if the pattern has more than one group. Empty matches
  490.         are included in the result.
  491.  
  492.         '''
  493.         pos = 0
  494.         end = len(source)
  495.         results = []
  496.         match = self.code.match
  497.         append = results.append
  498.         while pos <= end:
  499.             regs = match(source, pos, end, 0)
  500.             if not regs:
  501.                 break
  502.             
  503.             (i, j) = regs[0]
  504.             rest = regs[1:]
  505.             if not rest:
  506.                 gr = source[i:j]
  507.             elif len(rest) == 1:
  508.                 (a, b) = rest[0]
  509.                 gr = source[a:b]
  510.             else:
  511.                 gr = []
  512.                 for a, b in rest:
  513.                     gr.append(source[a:b])
  514.                 
  515.                 gr = tuple(gr)
  516.             append(gr)
  517.             pos = max(j, pos + 1)
  518.         return results
  519.  
  520.     
  521.     def __getinitargs__(self):
  522.         return (None, None, None, None)
  523.  
  524.     
  525.     def __getstate__(self):
  526.         return (self.pattern, self.flags, self.groupindex)
  527.  
  528.     
  529.     def __setstate__(self, statetuple):
  530.         self.pattern = statetuple[0]
  531.         self.flags = statetuple[1]
  532.         self.groupindex = statetuple[2]
  533.         self.code = apply(pcre_compile, statetuple)
  534.  
  535.  
  536.  
  537. class _Dummy:
  538.     group = None
  539.  
  540.  
  541. class MatchObject:
  542.     '''Holds a compiled regular expression pattern.
  543.  
  544.     Methods:
  545.     start      Return the index of the start of a matched substring.
  546.     end        Return the index of the end of a matched substring.
  547.     span       Return a tuple of (start, end) of a matched substring.
  548.     groups     Return a tuple of all the subgroups of the match.
  549.     group      Return one or more subgroups of the match.
  550.     groupdict  Return a dictionary of all the named subgroups of the match.
  551.  
  552.     '''
  553.     
  554.     def __init__(self, re, string, pos, endpos, regs):
  555.         self.re = re
  556.         self.string = string
  557.         self.pos = pos
  558.         self.endpos = endpos
  559.         self.regs = regs
  560.  
  561.     
  562.     def start(self, g = 0):
  563.         '''start([group=0]) -> int or None
  564.  
  565.         Return the index of the start of the substring matched by
  566.         group; group defaults to zero (meaning the whole matched
  567.         substring). Return -1 if group exists but did not contribute
  568.         to the match.
  569.  
  570.         '''
  571.         if type(g) == type(''):
  572.             
  573.             try:
  574.                 g = self.re.groupindex[g]
  575.             except (KeyError, TypeError):
  576.                 raise IndexError, 'group %s is undefined' % `g`
  577.  
  578.         
  579.         return self.regs[g][0]
  580.  
  581.     
  582.     def end(self, g = 0):
  583.         '''end([group=0]) -> int or None
  584.  
  585.         Return the indices of the end of the substring matched by
  586.         group; group defaults to zero (meaning the whole matched
  587.         substring). Return -1 if group exists but did not contribute
  588.         to the match.
  589.  
  590.         '''
  591.         if type(g) == type(''):
  592.             
  593.             try:
  594.                 g = self.re.groupindex[g]
  595.             except (KeyError, TypeError):
  596.                 raise IndexError, 'group %s is undefined' % `g`
  597.  
  598.         
  599.         return self.regs[g][1]
  600.  
  601.     
  602.     def span(self, g = 0):
  603.         '''span([group=0]) -> tuple
  604.  
  605.         Return the 2-tuple (m.start(group), m.end(group)). Note that
  606.         if group did not contribute to the match, this is (-1,
  607.         -1). Group defaults to zero (meaning the whole matched
  608.         substring).
  609.  
  610.         '''
  611.         if type(g) == type(''):
  612.             
  613.             try:
  614.                 g = self.re.groupindex[g]
  615.             except (KeyError, TypeError):
  616.                 raise IndexError, 'group %s is undefined' % `g`
  617.  
  618.         
  619.         return self.regs[g]
  620.  
  621.     
  622.     def groups(self, default = None):
  623.         '''groups([default=None]) -> tuple
  624.  
  625.         Return a tuple containing all the subgroups of the match, from
  626.         1 up to however many groups are in the pattern. The default
  627.         argument is used for groups that did not participate in the
  628.         match.
  629.  
  630.         '''
  631.         result = []
  632.         for g in range(1, self.re._num_regs):
  633.             (a, b) = self.regs[g]
  634.             if a == -1 or b == -1:
  635.                 result.append(default)
  636.             else:
  637.                 result.append(self.string[a:b])
  638.         
  639.         return tuple(result)
  640.  
  641.     
  642.     def group(self, *groups):
  643.         '''group([group1, group2, ...]) -> string or tuple
  644.  
  645.         Return one or more subgroups of the match. If there is a
  646.         single argument, the result is a single string; if there are
  647.         multiple arguments, the result is a tuple with one item per
  648.         argument. Without arguments, group1 defaults to zero (i.e. the
  649.         whole match is returned). If a groupN argument is zero, the
  650.         corresponding return value is the entire matching string; if
  651.         it is in the inclusive range [1..99], it is the string
  652.         matching the the corresponding parenthesized group. If a group
  653.         number is negative or larger than the number of groups defined
  654.         in the pattern, an IndexError exception is raised. If a group
  655.         is contained in a part of the pattern that did not match, the
  656.         corresponding result is None. If a group is contained in a
  657.         part of the pattern that matched multiple times, the last
  658.         match is returned.
  659.  
  660.         If the regular expression uses the (?P<name>...) syntax, the
  661.         groupN arguments may also be strings identifying groups by
  662.         their group name. If a string argument is not used as a group
  663.         name in the pattern, an IndexError exception is raised.
  664.  
  665.         '''
  666.         if len(groups) == 0:
  667.             groups = (0,)
  668.         
  669.         result = []
  670.         for g in groups:
  671.             if type(g) == type(''):
  672.                 
  673.                 try:
  674.                     g = self.re.groupindex[g]
  675.                 except (KeyError, TypeError):
  676.                     raise IndexError, 'group %s is undefined' % `g`
  677.  
  678.             
  679.             if g >= len(self.regs):
  680.                 raise IndexError, 'group %s is undefined' % `g`
  681.             
  682.             (a, b) = self.regs[g]
  683.             if a == -1 or b == -1:
  684.                 result.append(None)
  685.             else:
  686.                 result.append(self.string[a:b])
  687.         
  688.         if len(result) > 1:
  689.             return tuple(result)
  690.         elif len(result) == 1:
  691.             return result[0]
  692.         else:
  693.             return ()
  694.  
  695.     
  696.     def groupdict(self, default = None):
  697.         '''groupdict([default=None]) -> dictionary
  698.  
  699.         Return a dictionary containing all the named subgroups of the
  700.         match, keyed by the subgroup name. The default argument is
  701.         used for groups that did not participate in the match.
  702.  
  703.         '''
  704.         dict = { }
  705.         for name, index in self.re.groupindex.items():
  706.             (a, b) = self.regs[index]
  707.             if a == -1 or b == -1:
  708.                 dict[name] = default
  709.             else:
  710.                 dict[name] = self.string[a:b]
  711.         
  712.         return dict
  713.  
  714.  
  715.